package com.aaa.hospital.service.impl;

import com.aaa.hospital.mapper.ManageMapper;
import com.aaa.hospital.pojo.domain.Manage;
import com.aaa.hospital.pojo.query.ManageQuery;
import com.aaa.hospital.result.AjaxResult;
import com.aaa.hospital.service.ManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @Author: HJT
 * @DateTime: 2022/2/21 17:35
 * @Description: TODO
 */
@Service
public class ManageServiceImpl implements ManageService {
    @Autowired
    private ManageMapper manageMapper;
    @Override
    public AjaxResult queryManage(ManageQuery manageQuery) {
        List<Manage> manages = manageMapper.queryManage(manageQuery);
        Long aLong = manageMapper.queryManageTotal(manageQuery);
        HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("currentData",manages);
        objectObjectHashMap.put("totalCount",aLong);

        return AjaxResult.success(objectObjectHashMap);
    }

    @Override
    public AjaxResult addManage(Manage manage) {
        int i = manageMapper.addManage(manage);
        if (i>0){
            return AjaxResult.success();
        }
        return AjaxResult.fail();
    }

    @Override
    public AjaxResult deleteManage(Integer id) {
        int i = manageMapper.deleteManage(id);
        if (i>0){
            return AjaxResult.success();
        }
        return AjaxResult.fail();
    }

    @Override
    public AjaxResult getManage(Integer id) {
        Manage m = manageMapper.getManageById(id);
        return AjaxResult.success(m);
    }

    @Override
    public AjaxResult updateManage(Manage manage) {
        int i = manageMapper.updateManage(manage);
        if (i>0){
            return AjaxResult.success();
        }
        return AjaxResult.fail();
    }
}
